package com.wyx.mhl.service;

import com.wyx.mhl.dao.DiningTableDao;
import com.wyx.mhl.domain.diningTable;

import java.util.List;

/**
 * @author 王艺锡
 * @version 1.0
 * 该类用于对 diningTable表进行操作(调用 DiningTableDao )
 */
public class DiningTableService {
    private DiningTableDao diningTableDao = new DiningTableDao();

    //编写方法，返回当前坐位信息
    public List<diningTable> tableInfo(){
        return diningTableDao.queryMulti("select id,state from diningTable",diningTable.class);

    }

    //编写方法,查看是否有该餐桌信息
    public diningTable getDiningTable(int id){
        return diningTableDao.querySingle("select * from diningTable where id = ?",diningTable.class,id);
    }

    //编写方法,更新餐桌信息
    public boolean updateDiningTable(int id,String orderName,String orderTel){
        int update = diningTableDao.update("update diningTable set state = ?,orderName = ?,orderTel = ? where id = ?","已预订", orderName, orderTel, id);
        return update > 0;
    }

    //编写方法，更改餐桌状态
    public boolean updateDiningTableState(int tableId,String state){
        //更改餐桌信息
        int update = diningTableDao.update("update diningTable set state = ? where id = ?", state,tableId);
        return update > 0;
    }

    //编写方法，更改餐桌状态为空闲状态
    public boolean updateDiningTableStateToFree(int tableId){
        //更改餐桌信息
        int update = diningTableDao.update("update diningTable set state = '空',orderName = '',orderTel = '' where id = ?",tableId);
        return update > 0;
    }

}
